﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NTTDATA.BEENChina.ResultCertification.UI
{
    public partial class FormMonitor : Form
    {
        public FormMonitor()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            Logic.ActionMessage.GetInstance().ProcessMessage += new EventHandler<Logic.ActionEvent>(FormMonitor_ProcessMessage);
        }

        void FormMonitor_ProcessMessage(object sender, Logic.ActionEvent e)
        {
            ShowMessage(e.Message);
        }

        private readonly int _maxLineCount = 200;

        public void ShowMessage(string msg)
        { 

            if (textBox1.Lines.Length > _maxLineCount)
            {
                int c = 0;
                for (int i = 0; i < _maxLineCount / 2; i++)
                    c += textBox1.Lines[i].Length + Environment.NewLine.Length;

                textBox1.Text = textBox1.Text.Substring(c);
            }

            textBox1.AppendText(Environment.NewLine + msg);

        }

        private void FormMonitor_FormClosing(object sender, FormClosingEventArgs e)
        {
            Logic.ActionMessage.GetInstance().ProcessMessage -= new EventHandler<Logic.ActionEvent>(FormMonitor_ProcessMessage);

        }
    }
}
